package ca.unbc.cpsc672.fuzzy.rule;

import ca.unbc.cpsc672.fuzzy.function.MembershipFunction;

public class FuzzyOperator {
	public static boolean useMinMaxRule = true;

	public static double and(MembershipFunction f1, MembershipFunction f2,
			double x1, double x2) {
		double y1 = f1.calcProperbility(x1);
		double y2 = f2.calcProperbility(x2);
		if (useMinMaxRule)
			return Math.min(y1, y2);
		else
			return y1 * y2;
	}

	public static double or(MembershipFunction f1, MembershipFunction f2,
			double x1, double x2) {
		double y1 = f1.calcProperbility(x1);
		double y2 = f2.calcProperbility(x2);
		if (useMinMaxRule)
			return Math.max(y1, y2);
		else
			return y1 + y2 - y1 * y2;
	}

	public static double not(MembershipFunction f1, double x) {
		double y = f1.calcProperbility(x);
		return 1 - y;
	}
}
